#ifndef __ATHOME_CONFIG_H_
#define __ATHOME_CONFIG_H_

#include <string>
#include <crow.h>
#include <rwlock.h>
#include "utility.h"

class Config {
  public:
    Config() = default;
  public:
    bool init(const std::string& file);
    crow::json::rvalue config() const;
    crow::json::rvalue listen() const;
    const std::string& web_root();
    const std::string& web_index();
    const std::string& web_api_api_prefix();
    const std::string& api_file();
    crow::json::rvalue api_data() const;
    crow::json::rvalue api_apis() const;
  protected:
    void check_end_prefix(std::string& path) const;
  private:
    mutable rwlock::Lock lock_;
    mutable rwlock::Lock api_lock_;
    std::string file_;
    crow::json::rvalue json_;
    crow::json::rvalue api_;
    // cache
    std::string root_;
    std::string index_;
    std::string api_file_;
};

#endif // __ATHOME_CONFIG_H_